<?php
class Backstage{
	function __construct(){
		date_default_timezone_set('PRC');
	}
	private $path='../blogdata';
	//check_status,审核状态，checked为通过，checking为审核中，draft为草稿
	function blogCheckList($ck_op='checked'){
		if($ck_op=='all'){
			$sql='select user_id,title,create_time,check_status,content ';
			$sql.='from blog where check_status='.$ck_op;
		}
		else
			$sql='select id,user_id,title,create_time,content,check_status from blog where check_status="'.$ck_op.'" order by modify_time desc';	
		
		$r=$this->runMysql($sql);
		for($i=0;$r[$i];$i++){
			$user=$this->runMysql('select user from user where id='.$r[$i]['user_id']);
			$r[$i]['author']=$user[0]['user'];
			$r[$i]['title']=urldecode($r[$i]['title']);
		}
		return $r;
	}
	function blogStatusChange($aid,$status,$multi=false){
		if($multi){	
			//for($i=0,$count=count($aid))
				$sql='select user_id,title,create_time,check_status from blog where check_status='.$status;
		}else{
			$sql='select user_id,title,create_time';
		}
	}
	function runMysql($sql,$multi=false){	//为true时，执行多条语句
		include 'connect.inc.php';
		if($multi){
			$result->multi->query($sql);
		}else{
			$result=$mysqli->query($sql);
			if(is_object($result)){
				for($i=0;$row=$result->fetch_assoc();$i++){
					foreach($row as $key=>$value){
						$output[$i][$key]=$value;
					}
				}
				return $output;
			}
		}
			if($mysqli->error)
				echo $mysqli->error;
	}

}
